/*
Copyright 2024.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1

import (
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// EDIT THIS FILE!  THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required.  Any new fields you add must have json tags for the fields to be serialized.

// NodeTopoNetMetricSpec defines the desired state of NodeTopoNetMetric
type NodeTopoNetMetricSpec struct {
	NodeName string `json:"nodeName,omitempty"`
}

// NodeTopoNetMetricStatus defines the observed state of NodeTopoNetMetric
type NodeTopoNetMetricStatus struct {
	Latencies Latencies `json:"latencies,omitempty"`
}

// Latencies 存储所有节点到其他节点的延迟信息，其结构类似于下面的形式
// latencyMetrics:
//   - nodeName: node2
//     latency: [20ms, 30ms, 40ms, ...]
//   - nodeName: node3
//     latency: [10ms, 30ms, 40ms, ...]
type Latencies struct {
	LatencyMetrics []LatencyToNode `json:"latencyMetrics,omitempty"`
}

// LatencyToNode 存储在Latencies中的value
type LatencyToNode struct {
	// NodeName 对端节点名称
	NodeName string `json:"nodeName,omitempty"`

	// TODO:
	// 固定长度可以考虑由控制器在启动时决定
	// Latency 表示到 NodeName 的延迟,保证其长度为固定长度5
	Latency []string `json:"latency,omitempty"`
}

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status

// NodeTopoNetMetric is the Schema for the nodetoponetmetrics API
type NodeTopoNetMetric struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   NodeTopoNetMetricSpec   `json:"spec,omitempty"`
	Status NodeTopoNetMetricStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

// NodeTopoNetMetricList contains a list of NodeTopoNetMetric
type NodeTopoNetMetricList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []NodeTopoNetMetric `json:"items"`
}

func init() {
	SchemeBuilder.Register(&NodeTopoNetMetric{}, &NodeTopoNetMetricList{})
}
